<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>校验供应商</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<form id="formSet1">
			<div class="fieldset1 tabel_col clearFix">
				<div class="fieldBox col_66_auto">
					<div class="label">供应商属性</div>
					<div class="field">
						<select name="splAttrCd" id="splAttrCd" data-value=""
							validate="{required:true, select: true}">
							<c:forEach items="${searchSelectCsttypcdlist }" var="csttypcd" >
								<c:choose>
									<c:when test="${csttypcd.key == '2'}">
									 	<option value="${csttypcd.key }" selected>${csttypcd.value }</option>
									</c:when>
									<c:otherwise>
										<option value="${csttypcd.key }">${csttypcd.value }</option>
									</c:otherwise>
								</c:choose>
							</c:forEach>
						</select>
					</div>
				</div>
				<div class="fieldBox col_66_auto">
					<div class="label splCorp"  style="display:block">供应商名称</div>
					<div class="label splNatu"  style="display:none">姓名</div>
					<div class="field">
						<input name="splNm" id="splNm" type="text" class="ui-textbox"
							value="" validate="{required:true}">
					</div>
				</div>
				<!-- <div class="fieldBox col_66">
		                    <div class="label">税务登记号</div>
		                    <div class="field">
		                        <input name="taxRegNo" id="taxRegNo" type="text" class="ui-textbox" value="" validate="{}">
		                    </div>
		                </div> -->
				<div class="fieldBox col_66_auto">
					<!-- <div class="label splCorp" style="display:block">营业执照号</div> -->
					<div class="label splNatu" style="display:none">身份证号</div>
					<div class="field" id = "certNo" style="display:none">
						<input name="succ" id="succ" type="text"
							class="ui-textbox" value=""  >
					</div>
				</div>
			</div>
			
			<div class="btnsBox">
				<span id="hintSpan" style="color:#ff0000;display:none">系统未在工商网中查到此公司，请核对公司名称是否正确</span>
			</div>
			
			<div class="btnsBox">
                <span id="okBtn1" class="sq-button sq-button-round">确定</span>
                <span id="okBtn2" style="display:none;" class="sq-button sq-button-round">继续编辑</span>
                <span id="cancelBtn" class="sq-button sq-button-round">取消</span>
            </div>
		</form>
	</div>


	<script type="text/javascript">
$(function(){
	var formSet1 = $('#formSet1').ligerForm({
	        validate : true
	});
    SET_popupIframeHeight();
    btnIsShow();
    //add by zhaoyong 增加供应商属性切换事件
    splAttrCdChangeEvent();
});
var _mfrId = '${mfrId}';
var lxxz = '${lxxz}';
var prdmarks = '${prdmarks}';
var count = 0 ;
var isSplNmModify = 1;
function btnIsShow(){
}

//定义父级调用事件
//frameElement.dialog.onOk = function () {
	//check();
	//console.log(frameElement.dialog);
	//frameElement.dialog.options.buttons[0].text='继续编辑';
	//frameElement.dialog.options.ok='继续编辑';
	//frameElement.dialog.close();      
//}
           
//frameElement.dialog.onCancel = function () {
     //frameElement.dialog.close();
//}
$('#cancelBtn').click(function(){
	frameElement.dialog.close();
});
$('#okBtn1').click(function(){//确定
	isSplNmModify = 0;
	check();
});
$('#okBtn2').click(function(){//继续编辑
	isSplNmModify = 1;
	check();
});
$('#splNm').bind('input', function(){
	if(count < 2){
		$('#hintSpan').css('display', 'none');
		$('#okBtn1').css('display', 'inline-block');
		$('#okBtn2').css('display', 'none');
	}
});

function check(){
	var form = liger.get("formSet1");
	if (!form.valid()) {
    	top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
        return false; //验证不通过，不执行以下代码
    }
	var _splNm = $.trim($("#splNm").val());
	var _succ = $.trim($("#succ").val());
	var splAttrCd = $.trim($("#splAttrCd").val());
	var data = form.getData();
	//发送异步请求校验
	var wait_dialog;
	$.ajax({
		type: 'post',
		dataType:'json',
		data:data,
		url: '<%=path%>/product/splInfo/checkSpl.do',
		beforeSend: function(){
	          wait_dialog=top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	     },
		success:function(msg){
			var sign = 0;
			 wait_dialog.close();
			 if(msg.success == 1){
				 var attrCd = $("#splAttrCd").val();
				 console.log(attrCd)
				 if(attrCd != 1){
					 if(msg.info == 0){
						 sign = 1;
						 if(count < 2 && isSplNmModify == 0){
							count++;
							//top.$.ligerDialog.SQalert({content:"系统未在工商网中查到此公司，继续操作请点击确定", SQ_type: "success"});
							$('#hintSpan').css('display', 'block');
							$('#okBtn1').css('display', 'none');
							$('#okBtn2').css('display', 'inline-block');
							return ;
						 }
					 }
				 }
				var _id = msg.data;
				if(_id){
					top.$.ligerDialog.confirm("供应商已存在,是否跳转修改页面", function (flag) {
			   			if(flag == false){
			   				frameElement.dialog.close();
			   				return;
			   			}
			   			if(_mfrId==""){
			   				Add_navTab('PrdSpl_2'+_id,'修改供应商','<%=path%>/product/splInfo/toAddPage.do?id='+_id+'&isShowBigCustomer=1&isModify=1&splAttrCd='+splAttrCd);
			   			}else{
			   				Add_navTab('PrdSpl_2'+_id,'修改供应商','<%=path%>/product/splInfo/toAddPage.do?id='+_id+'&isShowBigCustomer=1&isModify=1&mfrId='+_mfrId+'&splAttrCd='+splAttrCd);
			   			}
			   			frameElement.dialog.close();
			   		});
				}else{
					//此处做判断是为了区分供应商管理与厂商备案供应商两个不同的新增供应商入口
					var postParam = {};
					postParam.mfrId = _mfrId;
					postParam.splNm = _splNm;
					postParam.succ = _succ;
					postParam.lxxz = lxxz;
					postParam.prdmarks = prdmarks;
					postParam.splAttrCd = splAttrCd;
					postParam.sign = sign;
					postParam.isSplNmModify = isSplNmModify;
					postParam.isModify = 1;
					postParam.isShowBigCustomer =1;
					Add_navTab_post("PrdSpl_1"+Date.parse(new Date()), "新增供应商", '<%=path%>/product/splInfo/toAddPage.do', parent.callback, postParam);
					/*if(_mfrId==""){
						Add_navTab("PrdSpl_1"+Date.parse(new Date()), "新增供应商", '<%=path%>/product/splInfo/toAddPage.do?mfrId='+_mfrId+'&splNm='+_splNm+'&succ='+_succ+'&lxxz='+lxxz+'&prdmarks='+prdmarks+'&splAttrCd='+splAttrCd+'&sign='+sign+'&isSplNmModify='+isSplNmModify,parent.callback);
					}else{
						Add_navTab("PrdSpl_1_1"+Date.parse(new Date()), "新增供应商", '<%=path%>/product/splInfo/toAddPage.do?mfrId='+_mfrId+'&splNm='+_splNm+'&succ='+_succ+'&lxxz='+lxxz+'&prdmarks='+prdmarks+'&splAttrCd='+splAttrCd+'&sign='+sign+'&isSplNmModify='+isSplNmModify,parent.callback);
					}*/
					frameElement.dialog.close();
				}
			 }else if(msg.success == 0){
				 top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 //frameElement.dialog.close();
			 }<%-- else if(msg.success == 0 && msg.data){//校验不成功,且有返回data(id) 说明供应商存在跳转
				var _audStsNm = msg.info;
				if(_audStsNm=="审核中"){
					top.$.ligerDialog.SQalert({content: "该供应商正在审核中 ,不允许修改！" , SQ_type: "warning" });
					return;
				}
				if(_audStsNm=="审核通过"){
					top.$.ligerDialog.SQalert({content: "该供应商已经审核通过 ,不允许修改！" , SQ_type: "warning" });
					return;
				}
				var _id = msg.data;
				if(_id){
					top.$.ligerDialog.confirm("供应商已存在,是否跳转修改页面", function (flag) {
			   			if(flag == false){
			   				frameElement.dialog.close();
			   				return;
			   			}
			   			if(_mfrId==""){
			   				Add_navTab('PrdSpl_2'+_id,'修改供应商','<%=path%>/product/splInfo/toAddPage.do?id='+_id+'&splAttrCd='+splAttrCd);
			   			}else{
			   				Add_navTab('PrdSpl_2'+_id,'修改供应商','<%=path%>/product/splInfo/toAddPage.do?id='+_id+'&mfrId='+_mfrId+'&splAttrCd='+splAttrCd);
			   			}
			   			frameElement.dialog.close();
			   		});
				}
			 } --%>
		}
	});
}

/**
 * @iframe_id iframe的id
 * @action post 地址
 * @title tab标签的显示名称
 * @params: Object
 *  - @postData 键值对json对象
 *  - @callback 回调方法
 */
function Add_navTab_post(iframe_id, title, action, receive, postData) {
	var _form = $('<form id="myForm" method="post" target="'+iframe_id+'" action="'+action+'" style="height: 0; overflow: hidden;"></form>')
	var _keys = Object.keys(postData)
	_keys.forEach(function (key) {
		_form.append('<input type="hidden" name="'+key+'" value="'+postData[key]+'" />')
	})
	top.$('body').append(_form)
	Add_navTab(iframe_id, title, '/', receive);
	_form.submit()
	_form.remove()
}

//客户类型选择事件
function splAttrCdChangeEvent(){
	$("#splAttrCd").change(function(event) {
		//var div_form = liger.get("formSet1");
        var typ =$(this).val();
        if (typ == CustomerConstant.CST_TYPE_NP_CD) {
        	$(".splNatu").css('display','block'); 
        	$(".splCorp").css('display','none'); 
        	$("#succ").rules("add",{required:true})
        	$("#certNo").css('display','block');
        }else if (typ == CustomerConstant.CST_TYPE_CORP_CD) {
        	//显示法人, 隐藏自然人
        	$(".splNatu").css('display','none'); 
        	$(".splCorp").css('display','block');
        	$("#succ").rules('remove','required')
        	$("#certNo").css('display','none');
        }else{
        	$.ligerDialog.SQalert({content: "客户类型无效!", SQ_type: "warning"});
        }
    });
}

</script>



</body>
</html>
